﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.Windsor;

namespace Project.Util.DependencyManagement
{
    public class ContainerManager
    {
        private readonly IWindsorContainer _container;

        public ContainerManager(IWindsorContainer container)
        {
            _container = container;
        }

        public IWindsorContainer Container
        {
            get { return _container; }
        }

        public void AddComponentInstance<TService>(TService service, string key = "", ComponentLifeStyle lifeStyle = ComponentLifeStyle.Singleton)
            where TService : class
        {
            _container.Register(Castle.MicroKernel.Registration.Component.For<TService>().Instance(service).LifeStyle.Singleton);
            //_container.Register(Castle.MicroKernel.Registration.Component.For<TService>().Instance(service)
            //    .Named(key)
            //    .LifeStyle.Singleton);
        }

        public T Resolve<T>(string key = "") where T : class
        {
            if (string.IsNullOrEmpty(key))
                return _container.Resolve<T>();
            return _container.Resolve<T>(key);
        }
    }
}
